import re

class PasswordStrengthChecker:
    def __init__(self):
        # 初始化时不需要额外操作，可根据需求添加
        pass

    def check_strength(self, password):
        # 初始化强度等级为弱
        strength = "弱"

        # 检查密码长度
        length = len(password)

        # 检查是否包含大写字母、小写字母、数字和特殊字符
        has_upper = re.search(r'[A-Z]', password)
        has_lower = re.search(r'[a-z]', password)
        has_digit = re.search(r'\d', password)
        has_special = re.search(r'[!@#$%^&*(),.?":{}|<>]', password)

        # 根据规则提升密码强度等级
        if length >= 8:
            if (has_upper and has_lower) and (has_digit or has_special):
                strength = "强"
            elif (has_upper or has_lower) and (has_digit or has_special):
                strength = "中"

        return strength

# 调用示例
if __name__ == "__main__":
    # 创建 PasswordStrengthChecker 类的实例
    checker = PasswordStrengthChecker()
    test_password = input("请输入密码: ")
    # 调用 check_strength 方法验证密码强度
    result = checker.check_strength(test_password)
    print(f"密码 '{test_password}' 的强度为: {result}")